BANKER'S AlGORITHM
Banker's Algorithm
Algorithm
1] Safety Algorithm:
Step 1- Let there be two vectors Work and Finish of length ‘m’ and ‘n’ in
a safety algorithm.
Initialize: Work = Available
Finish(i) = False; for i = 0, 1, 2, 3, 4… n - 1.
Step 2- Check the availability status for each type of resources (i),
such as:
Need(i) ≤ Work
Finish(i) == False
If the ‘i’ does not exist, go to step 4.
Step 3- Work = Work + Allocation(i) [to get new resource allocation]
Finish(i) = True
Go to step 2 to check the status of resource availability for the next process
Step 4- If Finish[i] == True; it means that the system is safe for all
processes.
2] Resource Request Algorithm:
Let Request(i) be the request array for process P(i).
Request(i) [j] = k means process P(i) wants k instances of resource type R(i).
When a request for resources is made by process P[i], the following actions are taken:
Step 1- If Request(i) ≤ Need(i)
Go to Step 2; otherwise, raise an error condition, since the process has exceeded its maximum claim.
Step 2- If Request(i) ≤ Available
Go to Step 3; otherwise, P(i) must wait, since the resources are not available.
Step 3- When the requested resource is allocated to the process by
changing state:
Available = Available – Request(i)
Allocation(i) = Allocation(i) + Request(i)
Need(i) = Need(i) – Request(i)